package vip.specimen.system.controller.config;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;
import vip.specimen.system.common.annotation.SystemJurisdiction;
import vip.specimen.system.datasource.entity.SystemEmailConfigEntity;
import vip.specimen.system.datasource.validation.SystemEmailConfigValidation;
import vip.specimen.system.result.JsonResult;
import vip.specimen.system.service.SystemEmailConfigService;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * *@Author: 余浪人
 * *@Date：2021/02/20 16:53
 * *@Email:yulangren520@Gmail.com
 * *@QQ:1368419640
 **/
@Api(tags = "配置管理")
@RestController
@RequestMapping(value = "/config/email")
public class EmailController {
    @Resource
    SystemEmailConfigService emailConfigService;

    @GetMapping
    @ApiOperation(value = "查看email配置", notes = "获取email配置信息")
    @RequiresPermissions(value = "config:email:select")
    @SystemJurisdiction(resourceType = "button", permissionName = "查看Email配置")
    public JsonResult<SystemEmailConfigEntity> emailGetConf() {
        return JsonResult.success(this.emailConfigService.getConf(), "success");
    }

    @PostMapping
    @RequiresPermissions(value = "config:email:update")
    @ApiOperation(value = "更新email配置", notes = "根据实体更新email配置信息")
    @SystemJurisdiction(resourceType = "button", permissionName = "更新Email配置")
    public JsonResult emailSaveConf(@RequestBody @Valid SystemEmailConfigValidation emailConfigValidation) {
        return JsonResult.success(this.emailConfigService.update(emailConfigValidation));
    }
}
